Ext
		.define(
				"core.doorctrl.controller.DoorCtrlController",
				{
					extend : "Ext.app.Controller",
					mixins : {
						suppleUtil : "core.util.SuppleUtil",
						messageUtil : "core.util.MessageUtil",
						formUtil : "core.util.FormUtil",
					},
					init : function() {
						var self = this;

						// 事件注册
						this
								.control({

									"panel[xtype=controllergrid]" : {
										select : this.checkEdit,
										deselect : this.checkEdit
									},

									"panel[xtype=doorctrl.addcontrollerform] button[ref=addController]" : {
										click : function(btn) {
//											var resDel = self
//													.ajax({
//														url : "basicinfo/room!validateRight.action"
//													});
//											if (false == resDel.success) {
//
//												Ext.Msg.alert('友情提示',
//														resDel.obj);
//												return false;
//
//											}
											var deptForm = btn
													.up("panel[xtype=doorctrl.addcontrollerform]");
											var formObj = deptForm.getForm();
											var params = self
													.getFormValue(formObj);
											if (formObj.isValid()) {
												var resObj = self
														.ajax({
															url : "doorcontr/isExist",
															params : params
														});
												if (resObj.success) {
													var resObj2 = self
															.ajax({
																url : "doorcontr/addDoorcontr",
																params : params
															});
													if (resObj2.success) {
														self.msgbox("添加控制器成功");
														Ext.ComponentQuery
																.query("panel[xtype=controllergrid] component[xtype=pagingtoolbar]")[0]
																.moveFirst();
														btn.ownerCt.ownerCt.ownerCt
																.close();
														return false;
													} else {
														Ext.Msg.alert("友情提示",
																resObj2.obj);
														return false;
													}
												} else {
													Ext.Msg.alert('友情提示',
															resObj.obj);
													return false;
												}
											} else {
												Ext.Msg.alert('友情提示',
														"请检查要添加的控制器信息");
												return false;
											}

											return false;

										}
									},
									"panel[xtype=doorctrl.addcontrollerform] button[ref=return]" : {
										click : function(btn) {
											btn.ownerCt.ownerCt.ownerCt.close();
											return false;
										}
									},

									"controllergrid button[ref=exportToExcel]" : {

										click : function(btn) {

											window.location.href = "basicinfo/doorcontroller!exportToExcel.action";

											return false;
										}
									},
									// 同步控制器数据
									"controllergrid button[ref=syncControllerDataClear]" : {

										click : function(btn) {
											var resDel = self
													.ajax({
														url : "basicinfo/room!validateRight.action"
													});
											if (false == resDel.success) {

												Ext.Msg.alert('友情提示',
														resDel.obj);
												return false;

											}
											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"同步控制器数据确认",
																"<center><h3>确定要先清除再同步所选的控制器的数据吗？<h3></center>",
																function(result) {
																	if (result == "yes") {

																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在发送同步控制器数据命令，请您稍等..."
																				});

																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!clearAndSyncControllerData.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();
																				self
																						.msgbox(resObj.obj);
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																		}
																	}

																});
											}

											return false;
										}
									},
									// 同步控制器数据
									"controllergrid button[ref=syncControllerData]" : {

										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"同步控制器数据确认",
																"<center><h3>确定要同步所选的控制器的数据吗？<h3></center>",
																function(result) {
																	if (result == "yes") {

																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在发送同步控制器数据命令，请您稍等..."
																				});

																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!syncControllerData.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();
																				self
																						.msgbox(resObj.obj);
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																		}
																	}

																});
											}

											return false;
										}
									},
									"controllergrid button[ref=syncappset]" : {

										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"同步应用群组确认",
																"<center><h3>确定要同步所选控制器的应用群组吗？<h3></center>",
																function(result) {
																	if (result == "yes") {
																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在发送同步控制器应用群组命令，请您稍等..."
																				});

																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!syncAppset.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();
																				self
																						.msgbox(resObj.obj);
																				return false;
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																				return false;
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																		}
																	}

																});
											} else {
												Ext.Msg.alert('友情提示',
														'请选择要同步应用群组的控制器');
												return false;
											}

											return false;
										}
									},
									"controllergrid button[ref=enablecontrollers]" : {

										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"启用控制器确认",
																"<center><h3>确定要启用所选的控制器吗？<h3></center>",
																function(result) {
																	if (result == "yes") {
																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在发送启用控制器命令，请您稍等..."
																				});
																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!enableDoorControllers.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();
																				var task = new Ext.util.DelayedTask(
																						function() {
																							var tbar = btn.ownerCt;
																							var controllerid2 = tbar.ownerCt
																									.down(
																											"textfield[name=controllerid2]")
																									.getValue();
																							var controllername = tbar.ownerCt
																									.down(
																											"textfield[name=controllername]")
																									.getValue();
																							var ipaddress = tbar.ownerCt
																									.down(
																											"textfield[name=ipaddress]")
																									.getValue();
																							var grid = tbar.ownerCt;

																							var _store = grid
																									.getStore();
																							_store
																									.clearFilter(false);
																							if (controllerid2 != null
																									&& controllerid2 != "") {
																								_store
																										.filter(
																												"controllerid",
																												controllerid2);
																							}
																							if (controllername != null
																									&& controllername != "") {
																								_store
																										.filter(
																												"controllername",
																												controllername);
																							}
																							if (ipaddress != null
																									&& ipaddress != "") {
																								_store
																										.filter(
																												"ipaddress",
																												ipaddress);
																							}
																							var proxy = _store
																									.getProxy();
																							proxy.extraParams = {
																								isdistinct : "false"

																							};

																							_store
																									.loadPage(1);
																							_store
																									.clearFilter(true);
																							return false;

																						});
																				task
																						.delay(5000);
																				self
																						.msgbox("启用控制器成功");
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																			return false;
																		}
																	}

																});
											} else {
												Ext.Msg.alert('友情提示',
														"请选择要启用的控制器");
												return false;
											}

											return false;
										}
									},
									"controllergrid button[ref=setoutbutton]" : {

										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"设置出门按钮确认",
																"<center><h3>确定要设置所选的控制器吗？<h3></center>",
																function(result) {
																	if (result == "yes") {
																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在设置出门按钮，请您稍等..."
																				});
																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!setOutButtons.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();

																				self
																						.msgbox(resObj.obj);
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																			return false;
																		}
																	}

																});
											} else {
												Ext.Msg.alert('友情提示',
														"请选择要启用的控制器");
												return false;
											}

											return false;
										}
									},
									"controllergrid button[ref=inverseOpenClose]" : {

										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"房门开关取反",
																"<center><h3>确定要取反所选控制器的房门状态吗？<h3></center>",
																function(result) {
																	if (result == "yes") {
																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在将房门开关状态取反，请您稍等..."
																				});
																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!inverseOpenClose.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();

																				self
																						.msgbox(resObj.obj);
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																			return false;
																		}
																	}

																});
											} else {
												Ext.Msg.alert('友情提示',
														"请选择要启用的控制器");
												return false;
											}

											return false;
										}
									},
									"controllergrid button[ref=clearShouQuan]" : {
										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"清空数据确认",
																"<center><h3>确定要清空所选控制器中的数据吗?<h3></center>",
																function(result) {
																	if (result == "yes") {
																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在清空控制器上的数据，请您稍等..."
																				});

																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		// 发送ajax请求
																		try {
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!clearShouQuan.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();
																				self
																						.msgbox(resObj.obj);
																				return false;
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																				return false;
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																		}
																	}

																});
											}

											return false;
										}
									},
									"controllergrid button[ref=disablecontrollers]" : {

										click : function(btn) {

											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length > 0) {

												// 封装ids数组
												Ext.Msg
														.confirm(
																"停用控制器确认",
																"<center><h3>确定要停用所选的控制器吗？<h3></center>",
																function(result) {
																	if (result == "yes") {
																		var myMask = new Ext.LoadMask(
																				Ext.ComponentQuery
																						.query("panel[xtype=centerview]")[0],
																				{
																					msg : "正在发送停用控制器命令，请您稍等..."
																				});

																		if (null != myMask)
																			myMask
																					.show();
																		var ids = new Array();
																		Ext
																				.each(
																						records,
																						function(
																								rec) {
																							var pkValue = rec
																									.get('controllerid');
																							ids
																									.push(pkValue);
																						});
																		try {
																			// 发送ajax请求
																			var resObj = self
																					.ajax({
																						url : "basicinfo/doorcontroller!disbaleDoorControllers.action",
																						params : {
																							ctrlids : ids
																									.join(",")

																						}
																					});
																			if (resObj.success) {
																				if (null != myMask)
																					myMask
																							.hide();
																				var task = new Ext.util.DelayedTask(
																						function() {
																							var tbar = btn.ownerCt;
																							var controllerid2 = tbar.ownerCt
																									.down(
																											"textfield[name=controllerid2]")
																									.getValue();
																							var controllername = tbar.ownerCt
																									.down(
																											"textfield[name=controllername]")
																									.getValue();
																							var ipaddress = tbar.ownerCt
																									.down(
																											"textfield[name=ipaddress]")
																									.getValue();
																							var grid = tbar.ownerCt;

																							var _store = grid
																									.getStore();
																							_store
																									.clearFilter(false);
																							if (controllerid2 != null
																									&& controllerid2 != "") {
																								_store
																										.filter(
																												"controllerid",
																												controllerid2);
																							}
																							if (controllername != null
																									&& controllername != "") {
																								_store
																										.filter(
																												"controllername",
																												controllername);
																							}
																							if (ipaddress != null
																									&& ipaddress != "") {
																								_store
																										.filter(
																												"ipaddress",
																												ipaddress);
																							}
																							var proxy = _store
																									.getProxy();
																							proxy.extraParams = {
																								isdistinct : "false"

																							};

																							_store
																									.loadPage(1);
																							_store
																									.clearFilter(true);
																							return false;

																						});
																				task
																						.delay(5000);
																				self
																						.msgbox("停用控制器成功");
																			} else {
																				if (null != myMask)
																					myMask
																							.hide();
																				Ext.Msg
																						.alert(
																								'友情提示',
																								resObj.obj);
																			}
																		} catch (e) {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							'友情提示',
																							"与服务器通讯异常");
																		}
																	}

																});
											} else {
												Ext.Msg.alert("友情提示",
														"请选择要停用的控制器");
												return false;
											}

											return false;
										}
									},
									"controllergrid button[ref=deleteControllers]" : {

										click : function(btn) {
											var resDel = self
													.ajax({
														url : "basicinfo/room!validateRight.action"
													});
											if (false == resDel.success) {

												Ext.Msg.alert('友情提示',
														resDel.obj);
												return false;

											}
											var grid = btn
													.up("panel[xtype=controllergrid]");
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length == 0) {
												Ext.Msg.alert('友情提示',
														"请您选择要删除的控制器");
												return false;
											}
											var ids = new Array();
											Ext.each(records, function(rec) {
												var pkValue = rec
														.get('controllerid');
												ids.push(pkValue);
											});
											// 发送ajax请求
											var validateObj = self
													.ajax({
														url : "basicinfo/doorcontroller!deleteDoorControllers.action",
														params : {
															ctrlids : ids
																	.join(",")

														}
													});
											if (false == validateObj.success) {
												Ext.Msg
														.alert("友情提示",
																"有房间正在使用该控制器，请先删除房间后再删除控制器！");
												return false;
											}
											if (records.length > 0) {
												// 封装ids数组
												Ext.Msg
														.confirm(
																"删除控制器确认",
																"<center><h3>确定要删除该的控制器吗？<h3></center>",
																function(result) {
																	if (result == "yes") {

																		// 发送ajax请求
																		var resObj = self
																				.ajax({
																					url : "basicinfo/doorcontroller!deleteDoorControllers.action",
																					params : {
																						ctrlids : ids
																								.join(",")

																					}
																				});
																		if (resObj.success) {
																			grid
																					.getStore()
																					.loadPage(
																							1);
																			self
																					.msgbox(resObj.obj);
																		} else {
																			Ext.Msg
																					.alert(
																							'友情提示',
																							resObj.obj);
																		}
																	}

																});
											}

											return false;
										}
									},
									"controllergrid button[ref=addController]" : {
										click : function(btn) {
//											var resDel = self
//													.ajax({
//														url : "basicinfo/room!validateRight.action"
//													});
//											if (false == resDel.success) {
//
//												Ext.Msg.alert('友情提示',
//														resDel.obj);
//												return false;
//
//											}
											var win = Ext
													.create(
															'Ext.window.Window',
															{
																title : '添加控制器',
																height : 400,
																width : 550,
																layout : 'fit',
																modal : true,
																items : [ {
																	xtype : 'doorctrl.addcontrollerform',
																	id : 'doorctrladdcontrollerform'
																} ]

															});

											win.show();
											return false;
										}
									},
									"controllergrid button[ref=abnormalControl]" : {
										click : function(btn) {
											var tbar = btn.ownerCt.ownerCt;
											var controllerid2 = tbar
													.down(
															"textfield[name=controllerid2]")
													.getValue();
											var controllername = tbar
													.down(
															"textfield[name=controllername]")
													.getValue();
											var ipaddress = tbar
													.down(
															"textfield[name=ipaddress]")
													.getValue();
											var grid = tbar;

											var _store = grid.getStore();
											_store.clearFilter(false);
											if (controllerid2 != null
													&& controllerid2 != "") {
												_store.filter("controllerid",
														controllerid2);
											}
											if (controllername != null
													&& controllername != "") {
												_store.filter("controllername",
														controllername);
											}
											if (ipaddress != null
													&& ipaddress != "") {
												_store.filter("ipaddress",
														ipaddress);
											}
											var proxy = _store.getProxy();
											proxy.extraParams = {
												isdistinct : "false",
												isabnormal : "true"

											};

											_store.loadPage(1);
											_store.clearFilter(true);
											return false;

										}
									},
									"controllergrid button[ref=onlyip]" : {
										click : function(btn) {
											var tbar = btn.ownerCt;
											var controllerid2 = tbar
													.down(
															"textfield[name=controllerid2]")
													.getValue();
											var controllername = tbar
													.down(
															"textfield[name=controllername]")
													.getValue();
											var ipaddress = tbar
													.down(
															"textfield[name=ipaddress]")
													.getValue();
											var grid = tbar.ownerCt;

											var _store = grid.getStore();
											_store.clearFilter(false);
											if (controllerid2 != null
													&& controllerid2 != "") {
												_store.filter("controllerid",
														controllerid2);
											}
											if (controllername != null
													&& controllername != "") {
												_store.filter("controllername",
														controllername);
											}
											if (ipaddress != null
													&& ipaddress != "") {
												_store.filter("ipaddress",
														ipaddress);
											}
											var proxy = _store.getProxy();
											proxy.extraParams = {
												isdistinct : "true",
												controller_id : controllerid2,
												controller_name : controllername,
												ip_address : ipaddress

											};

											_store.loadPage(1);
											_store.clearFilter(true);
											return false;

										}
									},
									//显示所有控制器 showAllControl
									"controllergrid button[ref=showAllControl]" : {

										click : function(btn) {
											var tbar = btn.ownerCt;
											var controllerid2 = tbar
													.down(
															"textfield[name=controllerid2]")
													.getValue();
											var controllername = tbar
													.down(
															"textfield[name=controllername]")
													.getValue();
											var ipaddress = tbar
													.down(
															"textfield[name=ipaddress]")
													.getValue();
											var grid = tbar.ownerCt;

											var _store = grid.getStore();
											_store.clearFilter(false);
											if (controllerid2 != null
													&& controllerid2 != "") {
												_store.filter("controller_id",
														controllerid2);
											}
											if (controllername != null
													&& controllername != "") {
												_store.filter("controller_name",
														controllername);
											}
											if (ipaddress != null
													&& ipaddress != "") {
												_store.filter("ip_address",
														ipaddress);
											}
											var proxy = _store.getProxy();
											proxy.extraParams = {
												isdistinct : "false",
												
												
											};

											_store.loadPage(1);
											_store.clearFilter(true);
											return false;

										}
									},
									/**
									 * 查找控制器信息
									 */
									"controllergrid button[ref=searchController]" : {

										click : function(btn) {
											var tbar = btn.ownerCt;
											var controllerid2 = tbar
													.down(
															"textfield[name=controllerid2]")
													.getValue();
											var controllername = tbar
													.down(
															"textfield[name=controllername]")
													.getValue();
											var ipaddress = tbar
													.down(
															"textfield[name=ipaddress]")
													.getValue();
											var grid = tbar.ownerCt;

											var _store = grid.getStore();
											_store.clearFilter(false);
											if (controllerid2 != null
													&& controllerid2 != "") {
												_store.filter("controllerid",
														controllerid2);
											}
											if (controllername != null
													&& controllername != "") {
												_store.filter("controllername",
														controllername);
											}
											if (ipaddress != null
													&& ipaddress != "") {
												_store.filter("ipaddress",
														ipaddress);
											}
											var proxy = _store.getProxy();
											proxy.extraParams = {
												isdistinct : "false",	
												controller_id : controllerid2,
												controller_name : controllername,
												ip_address : ipaddress
											};

											_store.loadPage(1);
											_store.clearFilter(true);
											return false;

										}
									},

									"controllergrid" : {

										itemdblclick : function(_grid, record,
												item, index, e, eOpts) {
											var window = Ext
													.create(
															'Ext.window.Window',
															{
																title : '修改门禁控制器',
																height : 400,
																width : 550,
																layout : 'fit',
																modal : true,
																items : [ {
																	xtype : 'doorctrl.controllerform',
																	id : 'doorctrlcontrollerform'
																} ]

															});

											// var grid = Ext.ComponentQuery
											// .query("component[xtype=gangweigrid]")[0];
											var form = window
													.down("panel[xtype=doorctrl.controllerform]");

											form.loadRecord(record);
											window.show();
											return false;
										}

									},

									"panel[xtype=doorctrl.controllerform] button[ref=return]" : {
										click : function(btn) {
											btn.ownerCt.ownerCt.ownerCt.close();
											return false;
										}
									},

									"panel[xtype=doorctrl.controllerform] button[ref=saveController]" : {
										click : function(btn) {
//											var resDel = self
//													.ajax({
//														url : "basicinfo/room!validateRight.action"
//
//													});
//											if (false == resDel.success) {
//
//												Ext.Msg.alert('友情提示',
//														resDel.obj);
//												return false;
//
//											}
											var ctrlForm = btn
													.up("panel[xtype=doorctrl.controllerform]");
											var formObj = ctrlForm.getForm();
											var params = self
													.getFormValue(formObj);
											if (formObj.isValid()) {

												var resObj2 = self
														.ajax({
															url : "doorcontr/updateDoorcontr",
															params : params
														});
												if (resObj2.success) {
													// self.msgbox(resObj2.obj);
													
													btn.ownerCt.ownerCt.ownerCt
															.close();
													var task = new Ext.util.DelayedTask(
															function() {
																var tbar = Ext.ComponentQuery
																.query("panel[xtype=controllergrid] component[xtype=toolbar]")[0];
																var controllerid2 = tbar.ownerCt
																		.down(
																				"textfield[name=controllerid2]")
																		.getValue();
																var controllername = tbar.ownerCt
																		.down(
																				"textfield[name=controllername]")
																		.getValue();
																var ipaddress = tbar.ownerCt
																		.down(
																				"textfield[name=ipaddress]")
																		.getValue();
																var grid = tbar.ownerCt;

																var _store = grid
																		.getStore();
																_store
																		.clearFilter(false);
																if (controllerid2 != null
																		&& controllerid2 != "") {
																	_store
																			.filter(
																					"controllerid",
																					controllerid2);
																}
																if (controllername != null
																		&& controllername != "") {
																	_store
																			.filter(
																					"controllername",
																					controllername);
																}
																if (ipaddress != null
																		&& ipaddress != "") {
																	_store
																			.filter(
																					"ipaddress",
																					ipaddress);
																}
																var proxy = _store
																		.getProxy();
																proxy.extraParams = {
																	isdistinct : "false"

																};

																_store
																		.loadPage(1);
																_store
																		.clearFilter(true);
																return false;

															});
													task.delay(500);
													return false;
												} else {
													Ext.Msg.alert("友情提示",
															resObj2.obj);
													return false;
												}

											} else {
												Ext.Msg.alert('友情提示',
														"请检查增加岗位的数据");
												return false;
											}

											return false;
										}
									},

									"controllergrid button[ref=testconn]" : {
										click : function(btn) {
											var grid = btn.ownerCt.ownerCt;
											var records = grid
													.getSelectionModel()
													.getSelection();
											if (records.length == 0) {
												Ext.Msg.alert('友情提示',
														"请选择要测试通讯的门禁控制器");
												return false;
											} else {

												var ids = new Array();
												Ext
														.each(
																records,
																function(rec) {
																	var pkValue = rec
																			.get('controllerid');
																	ids
																			.push(pkValue);
																});
												var myMask = new Ext.LoadMask(
														Ext.ComponentQuery
																.query("panel[xtype=centerview]")[0],
														{
															msg : "正在发送通讯测试命令，请您稍等..."
														});
												// 发送ajax请求
												try {
													if (null != myMask)
														myMask.show();
													var resObj = self
															.ajax({
																url : "basicinfo/doorcontroller!testConnByControllerid.action",
																params : {
																	ctrlids : ids
																			.join(",")

																}
															});

													if (resObj.success) {
														if (null != myMask)
															myMask.hide();
														var task = new Ext.util.DelayedTask(
																function() {
																	var tbar = btn.ownerCt;
																	var controllerid2 = tbar.ownerCt
																			.down(
																					"textfield[name=controllerid2]")
																			.getValue();
																	var controllername = tbar.ownerCt
																			.down(
																					"textfield[name=controllername]")
																			.getValue();
																	var ipaddress = tbar.ownerCt
																			.down(
																					"textfield[name=ipaddress]")
																			.getValue();
																	var grid = tbar.ownerCt;

																	var _store = grid
																			.getStore();
																	_store
																			.clearFilter(false);
																	if (controllerid2 != null
																			&& controllerid2 != "") {
																		_store
																				.filter(
																						"controllerid",
																						controllerid2);
																	}
																	if (controllername != null
																			&& controllername != "") {
																		_store
																				.filter(
																						"controllername",
																						controllername);
																	}
																	if (ipaddress != null
																			&& ipaddress != "") {
																		_store
																				.filter(
																						"ipaddress",
																						ipaddress);
																	}
																	var proxy = _store
																			.getProxy();
																	proxy.extraParams = {
																		isdistinct : "false"

																	};

																	_store
																			.loadPage(1);
																	_store
																			.clearFilter(true);
																	return false;

																});
														task.delay(5000);

														self.msgbox(resObj.obj);
													} else {
														if (null != myMask)
															myMask.hide();
														Ext.Msg.alert('友情提示',
																resObj.obj);
													}
												} catch (e) {
													if (null != myMask)
														myMask.hide();
												}

											}
											return false;
										}
									},
									"controllergrid button[ref=jiaoduitime]" : {
										click : function(btn) {
											// var grid = btn.ownerCt.ownerCt;
											// var store = grid.getStore();
											Ext.Msg
													.confirm(
															"友情提示",
															"<center>确定要同步所有控制器的时间吗？</center>",
															function(result) {
																if (result == "yes") {
																	// 发送ajax请求
																	var myMask = new Ext.LoadMask(
																			Ext.ComponentQuery
																					.query("panel[xtype=centerview]")[0],
																			{
																				msg : "正在同步所有控制器的时间，请您稍等..."
																			});

																	if (null != myMask)
																		myMask
																				.show();
																	try {
																		var resObj = self
																				.ajax({
																					url : "basicinfo/doorcontroller!syncControllerTime.action"

																				});
																		if (resObj.success) {
																			if (null != myMask)
																				myMask
																						.hide();
																			self
																					.msgbox(resObj.obj);

																		} else {
																			if (null != myMask)
																				myMask
																						.hide();
																			Ext.Msg
																					.alert(
																							"友情提示",
																							resObj.obj);
																		}
																	} catch (e) {
																		if (null != myMask)
																			myMask
																					.hide();
																		Ext.Msg
																				.alert(
																						"友情提示",
																						"与服务器通讯异常");
																	}
																}
																return false;
															});
										}
									}
								});
					},
					views : [ "core.doorctrl.view.MainLayout",
							"core.doorctrl.view.ControllerGrid",
							"core.doorctrl.view.AddControllerForm",
							"core.doorctrl.view.ControllerForm" ],
					stores : [ "core.doorctrl.store.ControllerStore" ],
					models : [ "core.doorctrl.model.ControllerModel" ],
					checkEdit : function() {
						var grid = Ext.ComponentQuery
								.query("panel[xtype=controllergrid]")[0];
						var num = grid.getSelectionModel().getSelection().length;
						var deleteControllers = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=deleteControllers]")[0];
						var testconn = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=testconn]")[0];
						var enablecontrollers = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=enablecontrollers]")[0];
						var disablecontrollers = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=disablecontrollers]")[0];
						var syncControllerData = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=syncControllerData]")[0];
						var syncappset = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=syncappset]")[0];

						var clearShouQuan = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=clearShouQuan]")[0];
						var syncControllerDataClear = Ext.ComponentQuery
								.query("panel[xtype=controllergrid] button[ref=syncControllerDataClear]")[0];
						if (syncControllerDataClear != null) {
							syncControllerDataClear.setDisabled(num == 0);
						}
						if (deleteControllers != null) {
							deleteControllers.setDisabled(num == 0);
						}
						if (testconn != null) {
							testconn.setDisabled(num == 0);
						}
						if (enablecontrollers != null) {
							enablecontrollers.setDisabled(num == 0);
						}
						if (disablecontrollers != null) {
							disablecontrollers.setDisabled(num == 0);
						}
						if (syncControllerData != null) {
							syncControllerData.setDisabled(num == 0);
						}
						if (syncappset != null) {
							syncappset.setDisabled(num == 0);
						}
						if (clearShouQuan != null) {
							clearShouQuan.setDisabled(num == 0);
						}
					}

				});